package ui;

import a4.Controller;
import a4.Main;
import data.Order;
import java.util.Scanner;
import user.Employee;

class EmployeeUI extends UI {

    EmployeeUI(Employee employee){
        user = employee;
    }
    
    public void employeeMenu() {
        do {
            System.out.println("\n1.Edit Menu\n"
                    + "2.Edit offers\n"
                    + "3.Check orders\n"
                    + "4.Logout");
            choise = input.next();
            if (choise.equals("1"))
                editMenu();
            else if (choise.equals("2"))
                editOffers();
            else if (choise.equals("3"))
                checkOrders();
            else if (choise.equals("4"))
                logout();
            else
                System.out.println("\nPlease, enter a valid option.\n");
        }
        while (choise.matches("[1-4]"));
    }

    private void editMenu() {
        do {
            System.out.println("1.Print the menu"
                    + "2.Create product\n"
                    + "3.Delete product\n"
                    + "4.Return to main menu");
            choise = input.next();
            if (choise.equals("1"))
                printProductList();
            else if (choise.equals("2"))
                addProduct();
            else if (choise.equals("3"))
                deleteProduct();
            else if (choise.equals("4"))
                return;
            else
                System.out.println("Please, choose a valid option.");
        }
        while ( !choise.matches("4") );
    }

        private void addProduct() {
            System.out.print("\nEnter the product name: ");
            String name = input.next();

            System.out.print("\nEnter the product description: ");
            String perigrafh = input.next();

            System.out.print("Enter the product price: ");
            float timh = input.nextFloat();

            System.out.print("\nEnter the product category: ");
            String kathgoria = input.next();

            Controller.addProduct(name, perigrafh,kathgoria, timh);
            System.out.print("\nThe product has been added successfully.\n");
        }
        
        private void deleteProduct() {
            printProductList();
            System.out.println("Parakalw epilekste proion:");
            int choosenProduct = input.nextInt();
            
            System.out.println("Eiste vevaios oti 8elete na diagrapsete to stoixeio:\n\t" + Main.productList.get(choosenProduct).getTitle() + "?(y/N)");
            choise = input.next();
  
            if (choise.equalsIgnoreCase("y")) {
                Controller.removeProduct(choosenProduct);
                System.out.println("To stoixeio diagrafhke me epityxia!");
            }
        }
        /**
         * void editOffers()
         * 
         * Epeksergasia Prosforwn
         */
    private void editOffers() {
        choise = UI.readString("1.Print offers\n"
                + "2.Add offer\n"
                + "3.Delete offer\n"
                + "4.Exodos", "Mh apodekth apanthsh", "[1-4]");
        
        if ( choise.equals("1") )
            printOfferList();
        else if ( choise.equals("2") ) {
            
        //   System.out.println("Enter the offer's item: ");
            String item = UI.readString("Enter the offer's item: ", "Mh apodekth prosfora", "[A-Za-z0-9 ]*");

            System.out.println("Enter the offers benchmark price: ");
            float price = input.nextFloat();

            Controller.addOffer(item, price);
        }
        else if (choise.equals("3")) {
            
            printOfferList();
            System.out.printf("Please choose the offer to be deleted: ");
            int choosenOffer =  readInt("Please choose the offer to be deleted: ","Mh apodekth epilogh",0,Main.offerList.size());

            System.out.printf("Epilegmenh prosfora:\n%10s %.2f\n", Main.offerList.get(choosenOffer).getItem(), Main.offerList.get(choosenOffer).getPrice());
            
            System.out.printf("Eiste vevaios oti 8elete na diagrapsete thn prosfora? (y/n)");
            choise = input.next();
            
            if (choise.equals("y") || choise.equals("Y"))
                Controller.deleteOffer(choosenOffer);
        }
    }

    private void checkOrders() {
        
    }

    private void printReceipt(Order order) {
        if (order.getProducts().size() > 0) {
            System.out.println("Pizzaria A.E \nApodeiksh");
            System.out.println("ItemID	Description");
            for (int i = 0; i < order.getProducts().size(); i++)
                System.out.println(order.getProducts().get(i).getID() + "  " + order.getProducts().get(i).getTitle() + "  / " + order.getProducts().get(i).getCost());
            System.out.println("TotalCost:	 / " + order.getTotalCost());
        }
    }
}
